package LeetCode.Simple;

/*
把字符串空格替换为%20
 */
public class Question002 {
    public static void main(String[] args) {
        System.out.println(new Question002().replaceSpace("1234 5678"));
    }
    public String replaceSpace(String s){
//        s.replace(" ","%20");
        char[] str1 = new char[s.length() * 3];
        int size = 0;
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == ' '){
                str1[size++] = '%';
                str1[size++] = '2';
                str1[size++] = '0';
                i++;
            }
            str1[size++] = s.charAt(i);
        }
        String newStr = new String(str1,0, size);
        return newStr;
    }
}
